﻿namespace MyManagement.Model
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
using MyManagement.Model.Repository;
    using Pedrosal.Components;

    /// <summary>
    /// Defines the entry point for using the object model.
    /// </summary>
    public class MyManagementRoot
    {
        private IProductRepository productRepository;
        private IProjectRepository projectRepository;
        private IBacklogItemCategoryRepository categoryRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="MyManagementRoot" /> class.
        /// </summary>
        public MyManagementRoot()
        {
            this.Backlog = new Backlog();

            this.productRepository = ServiceLocator.Resolve<IProductRepository>();
            if (this.productRepository == null)
            {
            }
            
            this.projectRepository = ServiceLocator.Resolve<IProjectRepository>();
            if (this.projectRepository == null)
            {
            }

            this.categoryRepository = ServiceLocator.Resolve<IBacklogItemCategoryRepository>();
            if (this.categoryRepository == null)
            {
            }
        }

        /// <summary>
        /// Gets or sets the backlog.
        /// </summary>
        /// <value>The backlog.</value>
        public Backlog Backlog
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the products.
        /// </summary>
        /// <value>The products.</value>
        public IQueryable<Product> Products
        {
            get
            {
                return this.productRepository.All;
            }            
        }

        /// <summary>
        /// Gets or sets the projects.
        /// </summary>
        /// <value>The projects.</value>
        public IQueryable<Project> Projects
        {
            get
            {
                return this.projectRepository.All;
            }            
        }

        /// <summary>
        /// Gets or sets the item categories.
        /// </summary>
        /// <value>The item categories.</value>
        public IQueryable<BacklogItemCategory> ItemCategories
        {
            get
            {
                return this.categoryRepository.All;
            }
        }
    }
}